package com.damai.controller;

import java.io.IOException;
import java.util.Map;

import org.beetl.core.Configuration;
import org.beetl.core.GroupTemplate;
import org.beetl.core.Template;
import org.beetl.core.resource.StringTemplateResourceLoader;

import com.damai.action.factories.SimpleJsonApiFactory;
import com.damai.annotation.Action;
import com.damai.annotation.Controller;
import com.damai.annotation.ReturnString;

@Controller(key = "generate")
public class GenerateService {
	GroupTemplate gt;
	public GenerateService() throws IOException {
		StringTemplateResourceLoader resourceLoader = new StringTemplateResourceLoader();
		Configuration cfg = Configuration.defaultConfiguration();
		gt = new GroupTemplate(resourceLoader, cfg);
	}
	
	@ReturnString
	@Action(value = SimpleJsonApiFactory.class)
	public String template(String template,Map<String, Object> data){
		Template t = gt.getTemplate(template);
		t.binding(data);
		String str = t.render();
		return str;
	}
	
}
